perm filename ALIO2.PAL[PNT,HE]2 blob sn#461262 filedate 1979-07-23 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00005 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	.SBTTL	Basic TTY input and output routines
C00003 00003	 TTY output routines  TYPSTW,TYPSTR, TYPDEC, TYPOCT, TYPCHR
C00010 00004	 Macros:  OUTSTR, NUMOUT, ASCIE, CRLF, ERRTRAP,OUTSTX,OUTCHR
C00014 00005	 IOINIT, INCHR, INSTR, system line buffers
C00018 ENDMK
C⊗;
.SBTTL	Basic TTY input and output routines
.EVEN

; TTY output routines  TYPSTW,TYPSTR, TYPDEC, TYPOCT, TYPCHR

;  Modified 5-Sep-74 by RF.  Originally written by KKP.
;  Modified 1979 by MSM

DATA
CURYXAL:0		;STORAGE FOR CURRENT POSITION OF AL DISPLAY
CURYXC:	0		;Y,X COORD FOR CAD
CADFLG: 0		;FLAG TO TELL IF CAD INSTRUCTION
TCHAR:	0		;temporary character
CODE

TYPSTW:	EVWAIT	CSLEVT	; typstr with consoleevent
	JSR	PC,TYPSTR
	EVSIG	CSLEVT

COMMENT ⊗ Output a string, ending with a zero character. Pointer to
start of string in R0.  Called in "simple" style. ⊗

TYPSTR:	MOV R0,R1	;R1 ← LOC[STRING]
	TST DSPOK	;DO WE NEED POINTY DISPLAY
	BNE 12$		;NO, do a regular typstr
	MOV #CAD,R0	;Yes, find right position
	MOV CURYXAL,CURYXC	;GET TO RIGHT Y-and X position
	JSR PC,TYPCAD	;output the direct address of cursor
	BR  2$
1$:	CMP #LF,R0	;Check if line feed
	BNE 5$
	MOVB #ALHOMX,CURYXAL+1	;Reset character position to first
	CMPB #COFF+24,CURYXAL	;Yes, now check if we are at bottom of screen
	BGT 4$
	MOV #CAD,R0	;Yes, so we reposition the cursor
	MOV ALHOMP,CURYXAL
	MOV CURYXAL,CURYXC
	JSR PC,TYPCAD
	BR  6$
4$:	INCB CURYXAL	;Increment line number
	MOV #CRD,R0	;shift the cursor down by 1 line
	JSR PC,TYPCHR
	JSR PC,TYPFIL
6$:	MOV #EOL,R0	;erase the line
	BR  3$
5$:	INCB CURYXAL+1	;Increment character position
3$:	JSR PC,TYPCHR	;Type this one character
2$:	MOVB (R1)+,R0	;R0 ← Next byte of string
	BNE 1$		;If more to come, repeat.
	RTS PC		;Done

11$:	JSR PC,TYPCHR
	CMP #LF,R0	;was it a LF?
	BEQ 13$		;yes, it was
12$:	MOVB (R1)+,R0	;R0←Next byte of string
	BNE 11$
	RTS PC		;Done
13$:	JSR PC,TYPFIL	; output fillers
	MOV #EOL,R0	;erase the line
	BR  11$		;and print out the char

PTYPSTR: MOV	R0,R1
	BR 2$
1$:	CMP #LF,R0	;Check if it is a linefeed
	BNE 5$
	JSR PC,TYPCHR	;and output it
	JSR PC,TYPFIL	;Now output filler nulls
	BR  2$
5$:	CMP #CAD,R0	;Check if it is a CAD
	BNE 6$
	MOVB (R1)+,CURYXC	;Tell it the line number
	MOVB (R1)+,CURYXC+1	;Tell it the character number
	JSR PC,TYPCAD
	BR  2$
6$:	JSR PC,TYPCHR
2$:	MOVB (R1)+,R0	;Get the next character
	BNE 1$
	RTS PC


COMMENT ⊗ Routines to output numbers.  Argument in R0.  TYPDEC
outputs in base 10, and TYPOCT in base 8.  Both use TYPDIG as a
subroutine, putting the digit in R0.  TYPCHR is a general purpose
character output routine.  It looks at OUTSW to see where to direct
the output. ⊗

DATA
RADIX::	12		;Starts out in decimal.
CODE

TYPDEC:	MOV #12,RADIX	;To output in base 10
	BR TYPDIG	;Go type it.
TYPOCT:	MOV #8,RADIX	;To output in base 8.
	BR TYPDIG	;Go type it.
TYPDIG::MOV R0,R1	;Need dividend in R1, with R0 clear.
	CLR R0		;Clear upper half of dividend.
	DIV RADIX,R0	;Divide argument in R0, R1 by radix.
	BEQ TYPOUT	;If quotient zero, then can print.
	MOV R1,-(SP)	;Else stack quotient
 	JSR PC,TYPDIG	;Recursive call.
	MOV (SP)+,R1	;Unstack last quotient
TYPOUT::ADD #'0,R1	;Form TTY code for digit
	MOV R1,R0	;Need argument for TYPCHR in R0.
TYPCHR::MFPD OUTSW	;VT05 or console?
	TST (SP)+
	BEQ 3$		;
	TSTB KBOS	;VT05: Is it available?
	BMI 2$		;Yes.
1$:
    .IFDF KERNEL
    .IFNZ KERNEL
	SLEEP #2	;No.  Sleep a while, try again
    .ENDC
    .ENDC
	BR TYPCHR	;
2$:	MOVB R0,KBOR	;Output a byte to it.
	RTS PC
3$:	MFPD OREG	;Console:  Ready?
	TSTB (SP)+
	BNE 1$		;No.
; following inserted by msm to prevent output of funny characters
	CMP #1,CADFLG
	BEQ TYPRET
	CMP #HOME,R0	;Is it going to top of screen?
	BEQ TYPRET
	CMP #CFILL,R0	;Is it a backspace or filler?
	BEQ TYPRET
	CMP #EOS,R0	;Is it clear screen
	BEQ TYPRET
	CMP #CAD,R0	;Is it direct cursor positioning?
	BEQ 9$
5$:	CMP #EOL,R0	;Is it a clear line?
	BEQ TYPRET
	CMP #CRD,R0	;Is it a move cursor down?
	BNE 10$
9$:	MOV  #CR,R0	;Put in a crlf
	JSR  PC,TYPCHR
	MOV #LF,R0	;Convert to line feed
10$:	MOV R0,-(SP)	;Yes.  Output a byte to it.
	MTPD OREG
	MOV #1,172566	;Wake up pdp10 by generating interrupt
TYPRET::RTS PC		;Return.

TYPFIL: CLR R0		;Type out 4 nulls as filler characters
	JSR PC,TYPCHR
	JSR PC,TYPCHR
	JSR PC,TYPCHR
	JSR PC,TYPCHR
	RTS PC

TYPCAD:	JSR PC,TYPCHR	;For direct cursor addressing, R0 already has CAD
			;CURYY Has Y pos,CURXX has y pos
	MOV #1,CADFLG	;Set CADFLG
	MOVB CURYXC,R0	;Output the y coord
	JSR PC,TYPCHR
	JSR PC,TYPFIL	;Output the filler
	MOVB CURYXC+1,R0;output x coord
	JSR PC,TYPCHR
	CLR CADFLG	;reset CADFLG
	RTS PC
; Macros:  OUTSTR, NUMOUT, ASCIE, CRLF, ERRTRAP,OUTSTX,OUTCHR

       .MACRO OUTSTX B	;type string starting at B
	MOV #B,R0	;Load up the string to be output
	JSR PC,TYPSTR	;Call the string output utility routine
       .ENDM

       .MACRO OUTCHR B	;output the character B
	MOVB #B,TCHAR
	MOV #TCHAR,R0
	JSR PC,TYPSTR
       .ENDM

       .MACRO OUTSTR B	;Type string starting at B.
	MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	MOV R1,-(SP)	;Save R1.
	MOV #B,R0	;Load up the string to be output
	JSR PC,TYPSTR	;Call the string output utility routine.
	MOV (SP)+,R1	;Restore R1.
	MOV (SP)+,R0	;Restore R0.
       .ENDM

       .MACRO NUMOUT	;Type out the number in AC0 with CVG using OUTBUF
	MOV R0,-(SP)	;Save the registers
	MOV R1,-(SP)
	STF AC0,-(SP)
	STF AC1,-(SP)
	MOV #OUTBUF,R0	;Use OUTBUF to construct the string
	JSR PC,CVG	;Convert floating point number to asc
	LDF (SP)+,AC1   ;Restore the floating point registers
	LDF (SP)+,AC0
	MOV #OUTBUF,R0	;Set pointer for i/o routine
	JSR PC,TYPSTR	;Type out the number
	MOV (SP)+,R1	;Restore the registers
	MOV (SP)+,R0
       .ENDM

       .MACRO ASCIE STR
       .ASCIZ STR
       .EVEN
       .ENDM

       .MACRO	CRLF
	OUTSTR CRLFX	;Carriage return, line feed.
       .ENDM
DATA

CRLFX::.ASCIZ /
/

RUGMES::ASCIE </π
--ONLY DDT CAN HELP YOU NOW!
π/>

CODE

ERRTRAP::
; Pointer to message is on stack.  Print it, restore state, go to DDT
	MOV R0,-(SP)	;Save R0.
	MOV R1,-(SP)	;Save R1.
    .IFDF KERNEL
    .IFNZ KERNEL
	EVWAIT CSLEVT	;Grab the console
    .ENDC
    .ENDC
	MOV #CRLFX,R0	;Move to new line
	JSR PC,TYPSTR	;
	MOV 6(SP),R0	;Type out message
	JSR PC,TYPSTR	;
	MOV #RUGMES,R0	;Type out RUGMES
	JSR PC,TYPSTR	;
    .IFDF KERNEL
    .IFNZ KERNEL
	EVSIG CSLEVT	;Release the console
    .ENDC
    .ENDC
	MOV #1,FRMDDT	;MSM, to tell POINTY that DDT might have upset display
	MOV (SP)+,R1	;Restore R1.
	MOV (SP)+,R0	;Restore R0.
	MOV (SP)+,(SP)	;put return address only on stack.
	BPT		;Breakpoint to DDT.
	RTS PC		;Return to calling point.

PUTLOC LERRTRAP, ERRTRAP

DATA
FRMDDT:	0
CODE
; IOINIT, INCHR, INSTR, system line buffers

DATA
CSLEVT::0		;Console interlock event
CODE
IOINIT::
    .IFDF KERNEL
    .IFNZ KERNEL
	EVMAK		;
	MOV (SP),CSLEVT	;
	EVSIG		;Make a console interlock event
    .ENDC
    .ENDC
	RTS PC		;

COMMENT ⊗ String byte pointer argument in R0.  A carriage return is
assumed to be the activation character. A rubout is a deleting
backspace character.  At the completion of this routine a null
character is placed at the end of the input string.  R0 then points
to the null character.  Registers used: R0 passes the argument, R1 is
garbaged.  ⊗

INCHR::	MFPD	OUTSW		;VT05 OR CONSOLE?
	TST	(SP)+
	BEQ 	1$
	TSTB	KBIS		;TEST IF KEYBOARD READY
	BEQ	INCHR		;WAIT TILL IT IS
	MOVB	KBIR,R1		;GET A CHARACTER
	BR	2$
1$:	MFPD	IREG		;BYTE FROM PDP10?
	MOV	(SP)+,R1
	BEQ	INCHR		;NO
	CLR	-(SP)
	MTPD	IREG
2$:	BIC     #177600,R1	;MASK OFF - MAKE IT 7 BITS
	RTS	PC

INSTR::	CLR	CCNT		;RESET CHARACTER COUNT
IN2::	JSR	PC,INCHR
	CMP	R1,#177		;COMPARE TO BS CHARACTER
	BNE	1$		;SKIP IF ITS NOT
	TST	CCNT		;CHECK IF ANY CHARACTERS IN BUFFER
	BEQ	IN2		;FORGET BACK SPACE IF NO CHAR.
	DEC     R0   		;REMOVE LAST CHARACTER IN BUFFER
	DEC	CCNT		;DECREMENT CHARACTER COUNT
	OUTSTR  DBS		;PERFORM A DELETING BACKSPACE
	BR      IN2
1$:	CMP	R1,#15		;COMPARE TO CR CHARACTER
	BEQ     2$   		;CONTINUE READING IF ITS NOT A CR
	CMP	R1,#40		;CHECK IF CHARACTER LEGAL
	BLT	IN2		;IGNOR IF IT IS
    	MOVB	R1,(R0)+	;SAVE THE CHARACTER
    	INC	CCNT		;INCREMENT CHARACTER COUNT
	MOV	R0,-(SP)	;ECHO THE CHARACTER
	MOV	R1,R0
	JSR	PC,TYPCHR
	MOV	(SP)+,R0
	BR 	IN2		;CONTINUE READING
2$:  	CRLF			;IF IT IS A CR, TYPE A CR AND LF
	MOVB	R1,(R0)+	;PUT A CR IN THE STRING
	MOVB    #0,(R0)		;PUT IN A NULL CHARACTER
	RTS	PC		;RETURN
DATA
CCNT::	0
DBS::	.BYTE	10,40,10,0

;System line buffers

INBUF::	.BLKW	42.
OUTBUF::.BLKW	42.
CURIN::	INBUF		;Current line pointer